package com.example.bitcoinnotificator;

import android.os.Bundle;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText TimeInterval;
	private EditText MinValue;
	private EditText MaxValue;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		TimeInterval = (EditText) findViewById(R.id.TimeInput);
		MinValue = (EditText) findViewById(R.id.MinValue);
		MaxValue = (EditText) findViewById(R.id.MaxValue);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void onClickRunService(View view) {
		if (view.getId()==R.id.Start) {
			
			if ((TimeInterval.getText().length() == 0)||(MinValue.getText().length() <= 0)||(MaxValue.getText().length() <= 0)) {
		        Toast.makeText(this, "Please enter a valid number",Toast.LENGTH_LONG).show();
		        return;
		    }
			
			double minValue = Double.parseDouble(MinValue.getText().toString());
		    double maxValue = Double.parseDouble(MaxValue.getText().toString());
		    int timeInterval = Integer.parseInt(TimeInterval.getText().toString());
		    
		    Intent intent = new Intent(this, CheckerService.class);
		    intent.putExtra(CheckerService.TIME,timeInterval);
		    intent.putExtra(CheckerService.MINVAL,minValue);
		    intent.putExtra(CheckerService.MAXVAL,maxValue);
		    //Toast.makeText(this, "clicked the shit starting intent bro!",Toast.LENGTH_LONG).show();
		    startService(intent);
		}
	}

}
